//
//  HRZAPIResult.m
//  EMarket
//
//  Created by 物联速通信息技术有限公司 on 2018/5/23.
//  Copyright © 2018 好日子. All rights reserved.
//

#import "HRZAPIResult.h"

// Controllers

// Models

// Views

// Vendors

// Categories

// Others

@interface HRZAPIResult ()

@end

@implementation HRZAPIResult

- (BOOL)success{
    return self.status == 200;
}

- (id)initWithDictionary:(NSDictionary *)dic
{
    if (self = [super init]) {
        @try {
            if (dic) {
                //              取出返回数据的状态码
                self.status = [[dic objectForKey:@"code"] intValue];
                //              提示信息
                self.message = [dic objectForKey:@"msg"];
                NSDictionary *data = [dic objectForKey:@"data"];
                //              返回数据
                self.dic = data;
            } else {
                //              没有返回数据
                self.message = @"网络错误";
                self.dic = nil;
                self.status = 102;  // 暂时定义无效的网络
            }
        }
        //接收到异常
        @catch (NSException *exception) {
            self.dic = dic;
            self.status = 0;
        }
        @finally {
        }
    }
    return self;
}

@end
